import requests
from api.reg_login_api import RegLoginApi
from api.kh_api import OpenAccountApi
from conm.uitils import assert_json,html_util
from bs4 import BeautifulSoup



class TestOpenAccount(object):
    url = None
    body = None

    def setup(self):
        # 创建session对象
        self.ses = requests.session()
        # 实例化封装接口请求的类
        self.login = RegLoginApi(self.ses)
        self.open = OpenAccountApi(self.ses)

    def teardown(self):
        # 关闭session对象
        self.ses.close()

    # 实名认证测试用例
    def test01_realname(self):
        # 实现登录接口
        self.login.user_login("13822138241","qqq123")
        # 实现实名认证接口
        resp = self.open.realname("刘某强","210802199705073370")

        # 断言
        assert_json(resp,200,200,"成功")



    # 开户测试用例
    def test02_open_account(self):
        bs = BeautifulSoup()
        # 实现登录接口
        self.login.user_login("13822138241", "qqq123")
        # 实现开户接口
        resp = self.open.open_account()





        # data = resp.json()
        # data_01 =data['description']['form']
        # print(data_01)
        # bs = BeautifulSoup(data_01,"html.parser")
        # self.url = bs.form.get("action")
        # print(f"url为,{self.url}")



        # 断言
        assert_json(resp,200,200,"form")


    # 第三方开户测试用例
    def test03_third_open_account(self):
        # 实现登录接口
        self.login.user_login("13822138241", "qqq123")
        # 实现开户接口
        resp = self.open.open_account()
        w = html_util(resp)
        url = w[0]
        body = w[1]
        # 实现第三方开户接口
        resp_s = self.open.third_open_account(url,body)
        # 断言
        assert "OK" in resp_s.text
